#ifndef GPS_UTILS_H
#define GPS_UTILS_H

#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
#include "gps.h"
#include <pthread.h>

// 模拟HAL库函数的宏定义
#define HAL_ADC_GetValue(channel) (rand() % 4096)
#define HAL_GPIO_WritePin(pin, state)
#define HAL_Delay(ms)
#define HAL_UART_Transmit(huart, pData, Size, Timeout)
#define GPIO_PIN_5 5
#define GPIO_PIN_6 6
#define GPIO_PIN_SET 1
#define GPS_LOG_FILE "gpslogger.txt"
#define GPIO_PIN_RESET 0

// 模块配置
#define ADC_MAX_VALUE  4095
#define VREF_VOLTAGE   3.3f
#define MAX_SPEED_KMH  200.0f
#define SPEED_THRESHOLD 120.0f
#define SAMPLING_PERIOD_MS 100
#define MAX_LOG_ENTRY 100
#define UART_TIMEOUT 100
#define LOG_FILE "vehicle_log.txt"

// 车辆传感模块结构体
typedef struct {
    float current_speed;
    bool alarm_active;
    uint32_t adc_raw_value;
    bool module_active;
    float fuel_level;
    float temperature;
} VehicleSensor_t;

// 全局变量声明
extern VehicleSensor_t vehicle_sensor;
extern uint32_t log_cycle_count;
extern const int gpslogs;
extern pthread_mutex_t lock;
extern volatile int run_gps, run_sensor;

void VehicleSensor_Init(void);
float VehicleSensor_ReadSpeed(void);
float VehicleSensor_ReadFuel(void);
float VehicleSensor_ReadTemperature(void);
void VehicleSensor_Log(void);
void VehicleSensor_Process(void);
float VehicleSensor_GetSpeed(void);
float VehicleSensor_GetFuel(void);
float VehicleSensor_GetTemperature(void);
bool VehicleSensor_IsAlarmActive(void);
bool VehicleSensor_IsModuleActive(void);
int read_nmea_sentence(char *buffer, size_t max_len);
int check_exit(void);
void GPS_Log(struct gps_tpv *tpv);
int GPSNavigator_Foreground(void);
void GPS_Background(void);
int VehicleSensor_Foreground(void);
void VehicleSensor_Background(void);
int MultimediaControl_Main(void);
void* function_a_thread(void* arg);
void* function_b_thread(void* arg);
void* function_gps_thread(void* arg);
void* function_sensor_thread(void* arg);

#endif /* GPS_UTILS_H */